
const M=require("ming_node")
const DictoryService=require("../../service/DictoryService")



app.post("/crmhelp/dictionary/add",async (req,res)=>{
    let {id=0,name=0,query_code=0,parent_id=0,gmt_create=new Date().format('yyyy-MM-dd hh:mm:ss'),gmt_modified=new Date().format('yyyy-MM-dd hh:mm:ss'),isdel=0,status=0,use_code=0,use_data=0,parse_code=0}=req.params;
    let r=await Db.doSql(`insert into t_dictionary (name,query_code,parent_id,gmt_create,gmt_modified,isdel,status,use_code,use_data,parse_code) values ('${name}','${query_code}','${parent_id}',now(),'${gmt_modified}','${isdel}','${status}','${use_code}','${use_data}','${parse_code}')`)
    res.send(M.successResult(r))
})


app.post("/crmhelp/dictionary/update",async (req,res)=>{
    let {id=0,name=0,query_code=0,parent_id=0,gmt_create=new Date().format('yyyy-MM-dd hh:mm:ss'),gmt_modified=new Date().format('yyyy-MM-dd hh:mm:ss'),isdel=0,status=0,use_code=0,use_data=0,parse_code=0}=req.params;
    let r=await Db.doSql(`update t_dictionary set 
             name='${name}',
             query_code='${query_code}',
             parent_id='${parent_id}',
             gmt_modified='${gmt_modified}',
             isdel='${isdel}',
             status='${status}',
             use_code='${use_code}',
             use_data='${use_data}',
             parse_code='${parse_code}' where id=${id}`)
    res.send(M.successResult(r))
})


app.get("/crmhelp/dictionary/list",async (req,res)=>{
    const {page=1,num=10,keywords,parent_id}= req.params
    let whereCase=" 1=1";
    if(keywords){
        whereCase=whereCase+` and name like '%${keywords}%'`;
    }
    if(parent_id){
        whereCase=whereCase+` and parent_id = ${parent_id}`;
    }
    let r=await  DictoryService.selectPage({page,num,queryCase:whereCase})
    res.send(M.successResult(r))
})


app.get("/getById",async (req,res)=>{

    let r= await DictoryService.selectById({id:3})
    res.send(r)
})